import django.forms as forms

from django_utils.form_helpers import DivForm,  FormValidator
import django_utils.form_widgets as form_widgets
import models

class CommentForm(DivForm):
    comment = forms.CharField(max_length = 500,  
                            min_length = 5, 
                            widget = form_widgets.BigTextarea(attrs={'class':'required full_textarea',  'minlength':'5'}), 
                            required = True, 
                            label = 'Post a comment')

class CompactCommentForm(DivForm):
    comment = forms.CharField(max_length = 500, 
                            min_length = 5, 
                            widget = form_widgets.SmallTextarea(attrs={'class':'required',  'minlength':'5'}), 
                            required = True, 
                            label = '')

def build_edit_comment_form(comment):
    base_fields = {'comment':  forms.CharField(max_length = 500,  
                            min_length = 5, 
                            widget = form_widgets.BigTextarea(attrs={'class':'required',  'minlength':'5'}), 
                            required = True, 
                            initial = comment.content, 
                            label = '')
                           }
                           
    def handle_edit(self,  user,  object):
        if self.data:
            object.log_edit(user,  self.cleaned_data['comment'])
            
    EditCommentForm = type('EditCommentForm',  (DivForm, ),  base_fields)
    EditCommentForm.handle_edit = handle_edit
    return EditCommentForm
